home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / MacMETH 3.2.3 / MEdit ƒ / Macros ƒ / Macros.MCR < prev   
Text File  |  1995-12-13  |  30KB  |  992 lines

  1. **********************************************************************************
  2. * This macro file is useful for Modula-2 programming. It allows you to
  3. * insert all important program-structures with one key.
  4. * derived from Pascal.Mcr of   Matthias Aebi  31.03.86
  5. * written           : 16.10.86   Alex Itten
  6. * Last modification : 20.10.86   Alex Itten
  7. *                      18.08.87   Andreas Fischlin
  8. *                      31.08.87   Andreas Fischlin to MEdit V1.54 adapted
  9. *                      11.02.88   A. Fischlin, Wrap and rearrange comment
  10. *                                 macro (22,36) added
  11. *                      11.09.88   Olivier Roth, adapted to pers. use
  12. *                      24.10.88   Olivier Roth, some bug fixes
  13. *                      30.01.89   Andreas Fischlin, adapted to pers. use
  14. *                                 and update to 1989 version made
  15. *                      13.02.89   Andreas Fischlin some minor changes in
  16. *                                 macro procedure (without VAR), and
  17. *                                 small format fixes in macro 5, 35, 44
  18. *                                 MacPlus version separated from Mac IIx
  19. *                                 version and making a generic version
  20. *                                 (see list of markers below)
  21. *                      14.02.89   Correction for Mac Plus
  22. *                      27.02.89   Thomas Nemecek, adapted to pers. use
  23. *                      10.06.89   Olivier Roth, menu layout & some short
  24. *                                 cuts (cmd-W is Close, Wrap->A).
  25. *                      23.08.89   A. Fischlin adapted to new versions of
  26. *                                 MacMETH, DM, and ModelWorks
  27. *                                 Case now Option^S instead of Option^A
  28. *                                 so that wrap in both versions may use
  29. *                                 Command^A resp. Option^A
  30. *                      25.10.89   O.R. removal of CONST, TYPE, VAR.
  31. *                                 Goto M2-Error added.
  32. *                      25.10.89   A.F. all versions corrected, new import
  33. *                                 list for ModelWorks 1.3 inserted
  34. *                      30.04.90   A.F. all versions corrected for DM 2.0,
  35. *                                 MacMETH 2.6+ and ModelWorks 2.0
  36. *                      15.09.90   A.F. versions corrected for DM 2.01 and
  37. *                                 ModelWorks 2.01
  38. *                      20.09.90   O.R.: version for MacMETH error support,
  39. *                                 complete revision.
  40. *                      01.10.90   O.R.: version 1.6 (with new MComp version)
  41. *                      26.10.90   O.R.: version 1.62 (with new MComp & MEdit)
  42. *                      09.11.90   O.R.: version 1.64 (with new MComp & MEdit)
  43. *                      24.11.90   O.R.: version 1.65 for students & ETH faculty
  44. *                      11.01.91   O.R.: version 1.66 for students & ETH faculty
  45. *                     12.06.91   A.F.: version 1.70 using no longer absolute
  46. *                                path to MacMETH but now relative path to
  47. *                                RAMSES shell
  48. *                      24.06.91     A.F.: Bug fix in macro «Find M2-Error» where
  49. *                                 WName result was returned inconsistently. Now
  50. *                                 using $1 as intermediate storage variable.
  51. *                      01.07.91   O.R.: version 1.71 for students & ETH faculty
  52. *                      12.07.91   O.R.: version 1.72 for students & ETH faculty
  53. *                      13.08.91   O.R.: version 1.73 for students & ETH faculty
  54. *                      20.11.91   A.F.: Minor version corrections and updates
  55. *                                 for RAMSES shell 1.02b4, MacMETH 3.0, DM 2.031,
  56. *                                 and ModelWorks 2.031.
  57. *                      13.01.92   D.G.: Updates for RAMSES Shell 1.2, 
  58. *                                 MacMETH 3.0, DM 2.2 and ModelWorks 2.2.
  59. *                      10/03/92   D.G.: Updates for RAMSES Shell 1.2b0, MacMETH 3.2 
  60. *                      31/08/92     A.F.: Version 1.79 
  61. *                     29/09/92   jth final release for MacMETH 3.2.
  62. *                      02/10/92     - J. Thoeny as user of this generic version added
  63. *                                Reconstruction of a generic version from
  64. *                                - J. Thoeny's new XX version
  65. *                                - Avoiding any non ASCII characters to allow
  66. *                                for easier port of code to MS-DOS PC and Unix 
  67. *                                machines
  68. *                      22/10/92     A.F.: Support for MiniRAMSESShell added, i.e.
  69. *                                mini* markers added
  70. *                     24/10/92   Launch shell sends now a comp message ('DMEv',231,0,0)
  71. *                      08/11/92     For RAMSES Mini shell support Cmd^0 must not
  72. *                                 send a 'MnCh' high level event.
  73. *                      13/11/92     Support for new MEdit version 1.8
  74. *                     02/12/92   Added Launch Shell and Simulate Macro
  75. *                      05/12/92     A.F.: Adapted for RAMSES 2.0
  76. *                     29/04/93   jth support for warning 263
  77. *                      07/06/93     A.F.: Adapted for RAMSES 2.2
  78. *                     29/04/93   jth MacMETH 3.2.2
  79. *                     12/09/95   af MacMETH 3.2.3
  80. *
  81. **********************************************************************************
  82. * Versions:
  83. *    M2-Generic(1.80).MCR
  84. *    MComp 1.40
  85. *    MEdit 1.80
  86. **********************************************************************************
  87. * Legend:
  88. *  Δ            - Shift
  89. *  xNum         - key x on numeric key pad
  90. *  Opt          - Option (alt) key
  91. *  ^            - between two keys means press simultaneously
  92. *  CursLeft     - Cursor Left
  93. *  CursRight    - Cursor Right
  94. *  CursUp       - Cursor Up
  95. *  CursDown     - Cursor Down
  96. *
  97. *  Version markers: This file is a generic macro version.  The beginning 
  98. *                    of the lines are marked with a particular comment string
  99. *                    see list below.  To produce a particular version of these
  100. *                    macros simply remove all markers of the particular kind
  101. *                    to make the particular lines active.  Otherwise the macro
  102. *                    compiler will treat them as a comment only.  Warning: Be
  103. *                    careful not to destroy this generic version while making
  104. *                    a particular version (Use menu command Save as... and NOT
  105. *                    Save!).
  106. *  List of used markers (first '*' is omitted to allow for global remove, so
  107. *                         that the list below is not destroyed while producing
  108. *                         a particular version)
  109. *    af*        - Line used in A. Fischlin's version for any Mac
  110. *    jt*        - Line used in J. Thoeny's version for any Mac
  111. *    or*        - Line used in O. Roth's version for any Mac SE & II sg
  112. *    tn*        - Line used in T. Nemecek's version for any Mac II sg
  113. *    XX*        - Line used in version for: student, staff & faculty of ETHZ
  114. *    mini*      - Line used in version for Mini RAMSES Shell
  115. *  legend: sg = swiss german keyboard, us = us ascii keyboard
  116. **********************************************************************************
  117.  
  118. *
  119. * Globally used string resources ('STR '):
  120. * ID 0-4
  121. *
  122. * Globally used string variables:
  123. *
  124. * $9 : path to folder containing "ErrList.DOK" (relative to MacMETH folder)
  125. * $8 : name of the M2-shell
  126. * $7 : last name of user
  127. * $6 : first name of user
  128. * $5 : pattern expression for finding M2-error mark
  129. * $4 : 
  130. * Locally used:
  131. * $3 : div.
  132. * $2 : procedure name
  133. * $1 : div.
  134. * $0 : module name
  135.  
  136. *
  137. * Locally used numeric variables:
  138. * #0, #1, #2, #6-#9
  139. * --------------------------------------------------------------------------------
  140.  
  141.  
  142.  
  143. * 01
  144. * Find all compiled M2 files and open the erroneous/first in list
  145. * NOTE: this is the autoexec macro!
  146. !"Open work file[s]/0" • {
  147. *   at least one window must be open for autoexec macro
  148. *    New;  IF Window(1)  { Window(0);  Close };
  149.     Set( $7, GetStr(0) );
  150.     IF Len($7) = 0 {
  151. * adapt here for your configuration:
  152. * *********************************
  153. *jt*        Set($8," MacMETH 3.2.3");        Set($9,":M2Tools 3.2.3:");      Set($7,"Thoeny");                 Set($6,"Juerg");
  154. *or*        Set($8," MacMETH 3.2.3");        Set($9,":M2Tools 3.2.3:");      Set($7,"Roth");                   Set($6,"Olivier");
  155. *af*        Set($8," RMSMacMETH 3.2.3");    Set($9,":M2Tools 3.2.3:");      Set($7,"Fischlin");               Set($6,"Andreas");
  156. *tn*        Set($8," MacMETH 3.2.3");        Set($9,":M2Tools 3.2.3:");      Set($7,"Nemecek");                Set($6,"Thomas");
  157.         Set($8," MacMETH 3.2.3");        Set($9,":M2Tools 3.2.3:");      Set($7,"(*.Your last name.*)"); Set($6,"(*.Your first name.*)");
  158. * *********************************
  159.         Call(09);  }
  160.     ELSE  {
  161.         Set( $6, GetStr(1) );
  162.         Set( $8, GetStr(2) );
  163.         Set( $9, GetStr(3) );
  164.     };
  165.     Set($5,"†[ 0-9][ 0-9][0-9]†");
  166.     IF NOT Open( "err.DAT")  {
  167.       Alert( Concat( "Can't find and open the Modula-2 compilation error file: '", "err.DAT", "'" ) );
  168.       Alert( "Move MEdit and/or compile your Modula-2 source file(s)" );  }
  169.     ELSE  {
  170.       Set(#0,0);
  171.       Select(0,0);
  172.       Set(#1,AbsPos);
  173.       WHILE Find("¿")  {
  174.         Set(#2, AbsPos-#1 );  Set(#2, #2 MOD 7 );
  175.         IF #2 = 0  {
  176. *          i.e. filename mark found
  177. *         NOTE: ".*[]" contains 0C in brackets!
  178.           EFind(".*[]");
  179.           Select(L.,C.|L.,C:-1);
  180.           Set($1,$S);
  181.           Select(L.,C:+1|L.,C:+2);
  182.           Set(#1,AbsPos);        
  183.           IF StrCmp($S,"¡",1) = 0  {
  184.             IF NOT Open($1)  {
  185.               Alert( Concat("Can't find and open source file '", $1, "' containing Modula-2 errors!") );
  186.               Alert( "Try Macro 'Configure' and/or compile your Modula-2 source file(s)" );
  187.               SelAbs(AbsPos+1);  }
  188.             ELSE  {
  189.               Set(#0,#0+1);
  190.               Window(#0);
  191.             };
  192.           };
  193.           SelAbs(AbsPos-1);
  194.         };
  195.       };
  196.       IF #0 = 0 {
  197. *       no file with compilation errors, open first:
  198.         Select(0,1);
  199.         EFind(".*[]");
  200.         Select(L.,C.|L.,C:-1);
  201.         Set($1,$S);
  202.         IF NOT Open($1)  {
  203.           Alert( Concat("Can't find and open Modula-2 file '", $1, "'") );
  204.           Alert( "Try Macro 'Configure' and/or compile your Modula-2 source file(s)" );  }
  205.         ELSE  {
  206.           Set(#0,#0+1);
  207.           Window(#0);
  208.         };
  209.       };
  210.       Close;
  211.       IF #0 > 0  Call(02);
  212.     };
  213. };
  214.  
  215. * 02
  216. * jumps ,to the next Modula-2 error mark and displays an alert
  217. "Find next error/E" {
  218.     IF Len($S) > 5 Select(L.,C:-5|L.,C:);
  219.     IF EFind ($5) {
  220.       Select(L.,C.|L.,C:)!;
  221.       Set($3,SubStr($S,2,3));
  222.       Set(#8,Val($3));
  223.       IF #8 = 263 {
  224.           Select(L.,C<|L.,C:);
  225.           Select(L.,C.-1|L.,C:);
  226.           Select(L.,C<|L.,C:);
  227.           Select(L.,C>|L.,C:);
  228.           Select(L.,C.-1|L.,C:);
  229.         Set(#7,Ord(SubStr($S,1,1)));
  230.         IF #7 = Ord("=")  {
  231.               Select(L.,C.-1|L.,C:);
  232.             Select(L.,C<|L.,C:);
  233.         } ELSE {
  234.             IF NOT #7 = Ord(",") AND NOT #7 = Ord(" ") {
  235.                 Select(L.,C.+1|L.,C:);
  236.             };
  237.         };
  238.           IF Len($S) < 5{
  239.               Select(L.,C:-5|L.,C:);
  240.               Select(L.,C<|L.,C:);
  241.           };
  242.           Beep;
  243.       };
  244.       Set(#7,0);  Set(#8,0);  Set(#9,0);
  245.       WHILE #8 = 0 AND #7 = 0  {
  246.         IF Window(#9)  {
  247.           IF StrCmp(WName,"ErrList.DOK",0) = 0  Set(#8,1);
  248.         }
  249.         ELSE
  250.           Set(#7,1);
  251.         Set(#9,#9+1);
  252.       };
  253.       IF #8 = 0  {
  254.         IF Open( Concat($9,"ErrList.DOK") )  {
  255.           PlaceW( ScrH-50, 2, ScrH-2, 500 );
  256.           Set(#8,1);
  257.         }
  258.         ELSE
  259.           Alert( Concat("Can't find and open compilation error message file '",$9,"ErrList.DOK'"));
  260.       };
  261.       IF #8 = 1  {
  262.         Select(VAL($3)-40,0);
  263.         Set( $1, Concat( "^- ", $3, " .*" ) );
  264.         EFind( $1 )!;
  265.         IF NOT Val($3) = 263 {
  266.             EAlert( "Modula-2 Error:", SubStr($S,8,255) );
  267.         };
  268.         Window(#7);
  269.       };
  270.     }
  271.     ELSE  {
  272.         Beep;
  273.         Select(L.,C.|L:,C:)!;
  274.     }
  275. };
  276.  
  277.  
  278.  
  279. * 03
  280. * Clear error marks, close and Launch Modula-2 shell
  281. "Clear, save & launch/1" {
  282.     Call(07);
  283. * Compile/simulate message 'COMP'  ≈  17231 = C + O = 43H = 4FH;  19792 = M + P = 4DH + 50H 
  284.     IF POSTHL("RAMS","DMEv",17231, 19792, 0) ELSE IF POSTHL("ETHM","DMEv",17231, 19792, 0);
  285. *    IF POSTHL("RAMS","MnCh",129,5,0) ELSE IF POSTHL("ETHM","MnCh",129,5,0);
  286.     Launch( GetStr(2) );
  287. };
  288.  
  289. * --------------------------------------------------------------------------------
  290. * 04
  291. * insert a line in the menu
  292. "-" {};
  293.  
  294. * 05
  295. * Launch Modula-2 shell and Simulate
  296. "Launch shell & simulate/2" •{
  297. * Compile/simulate message 'COMP'  ≈  17231 = C + O = 43H = 4FH;  19792 = M + P = 4DH + 50H 
  298.     IF POSTHL("RAMS","DMEv",17231, 19792, 0) ELSE IF POSTHL("ETHM","DMEv",17231, 19792, 0);
  299.     Launch( GetStr(2) );
  300. };
  301.  
  302.  
  303. * 06
  304. * Launch Modula-2 shell
  305. "Launch shell/3" •{
  306.     Launch( GetStr(2) );
  307. };
  308.  
  309.  
  310. * 07
  311. * Close Modula-2-source file
  312. "Clear error marks & save/8" {
  313.     Select(0,0);
  314.     WHILE EFind ($5)   Clear;
  315.     Save;
  316.     Select(0,0);
  317.     Close;
  318. };
  319.  
  320. * 08
  321. * Remove Modula-2-error marks
  322. * alternate (invisible) errmark: EFIND("")
  323. "Clear error marks/9" {
  324.     Sect(0);
  325.     Select(0,0);
  326.     WHILE EFind ($5)   Clear;
  327. };
  328.  
  329.  
  330.  
  331. * 09
  332. "Configure" •{
  333.     Set( $4, GetStr(0) );
  334.     IF NOT Len($4) = 0  Set($7,$4);
  335.     IF Prompt( "Your last name:", $7 )  {
  336.         IF NOT Len($4) = 0  Set( $6, GetStr(1) );
  337.         IF Prompt( "Your first name:", $6 )  {
  338.             IF NOT Len($4) = 0  Set( $9, GetStr(3) );
  339.             IF Prompt( "Relative path to 'ErrList.DOK':", $9 )  {
  340.                 IF NOT Len($4) = 0  Set( $8, GetStr(2) );
  341.                 IF Prompt( "Name of the Modula-2 (MacMETH) shell:", $8 )  {
  342.                     PutStr( 0, $7 );
  343.                     PutStr( 1, $6 );
  344.                     PutStr( 2, $8 );
  345.                     PutStr( 3, $9 );
  346.                 }
  347.             }
  348.         }
  349.     }
  350. };
  351.  
  352.  
  353. * --------------------------------------------------------------------------------
  354. * 10
  355. * insert a line in the menu
  356. "-" {};
  357.  
  358. * 11
  359. * Insert a DEFINITION MODULE template (Option^M)
  360. "MODULE DEF          Opt M" 346 •{
  361.   IF Prompt("Enter DEF Module name ",$0) {
  362.     New;
  363.     Push;
  364.     Insert("DEFINITION MODULE ");
  365.     Insert($0);
  366.     Insert(";\N");
  367.     Insert("\N");
  368.     Insert("  (*******************************************************************\N");
  369.     Insert("\N");
  370.     Insert("    Module  ");  Insert($0);  Insert("     (Version 1.0)\N");
  371.     Insert("\N");
  372.     Insert(Concat("              Copyright (c) 1993 by ",$6," ",$7," and Swiss\N"));
  373.     Insert("              Federal Institute of Technology Zürich ETHZ\N");
  374.     Insert("\N");
  375.     Insert("      Purpose (*.  purpose  .*)\N");
  376.     Insert("              \N");
  377.     Insert("      Remarks (*.  remarks.  .*)\N");
  378.     Insert("              \N");
  379.     Insert("      Programming\N");
  380.     Insert("\N");
  381. *af*    Insert("          o Design and Implementation\N");
  382. *jt*    Insert("          o Design\N");
  383. *or*    Insert("          o Design and Implementation\N");
  384. *tn*    Insert("          o Design\N");
  385.     Insert("          o Design\N");
  386.     Set($3,Concat("              ",SubStr($6,0,1),". ",$7,"         ",Date(2),"\N\N"));
  387.     Insert($3);
  388. *jt*    Insert("          o Implementation\N");  Insert($3);
  389. *tn*    Insert("          o Implementation\N");  Insert($3);
  390.     Insert("          o Implementation\N");  Insert($3);
  391.     Insert("              \N");
  392. *af*     Insert("          Systems Ecology\N");
  393. *jt*     Insert("          Systems Ecology\N");
  394. *or*     Insert("          Systems Ecology\N");
  395. *tn*     Insert("          Systems Ecology\N");
  396. *af*     Insert("          Institute of Terrestrial Ecology\N");
  397. *af*     Insert("          Department of Environmental Sciences\N");
  398. *jt*     Insert("          Department of Environmental Sciences\N");
  399. *or*     Insert("          Department of Environmental Sciences\N");
  400. *tn*     Insert("          Department of Environmental Sciences\N");
  401.     Insert("          Swiss Federal Institute of Technology Zurich ETHZ\N");
  402. *af*     Insert("          Grabenstr. 3\N");
  403. *jt*     Insert("          Grabenstr. 3\N");
  404. *or*     Insert("          Grabenstr. 3\N");
  405. *tn*     Insert("          Grabenstr. 3\N");
  406.     Insert("          CH-8952 Schlieren/Zurich\N");
  407.     Insert("          Switzerland\N");
  408.     Insert("\N");
  409.     Insert("          Last revision of definition:  ");
  410.     Insert(Concat(Date(2),"  ",SubStr($6,0,1),SubStr($7,0,1),"\N"));
  411.     Insert("\N");
  412.     Insert("  *******************************************************************)\N");
  413.     Insert("\N");
  414.     Insert("\N");
  415.     Insert("  (*.  .*)\N");
  416.     Insert("\N");
  417.     Insert("END ");
  418.     Insert($0);
  419.     Insert(".\N");
  420.     Call(38);
  421.     QSavAs(Concat($0,".DEF"));
  422.   };
  423. };
  424.  
  425.  
  426. * 12
  427. * Insert an IMPLEMENTATION MODULE template
  428. * [for DEF: Opt-M]
  429. "MODULE MOD/M" •{
  430.     IF Prompt("Enter Module name ",$0)  {
  431.       New;
  432.       Push;
  433.       Insert("(*. IMPLEMENTATION  .*)MODULE ");  Insert($0);  Insert(";\N\N");
  434.       Call(36);
  435.       Insert("\N");
  436.       Insert("\N");
  437.       Insert("BEGIN\N");
  438.       Insert("  (*.Statement.*)\N");
  439.       Insert("END ");
  440.       Insert($0);
  441.       Insert(".\N");
  442.       Call(38);
  443.       QSavAs(Concat($0,".MOD"));
  444.     };
  445. };
  446.  
  447.  
  448. * 13
  449. * Derive an empty implementation module from a correct definition module
  450. * NOTE: this version does NOT function CORRECTLY FOR:
  451. *       - syntactically incorrect DEF modules, e.g: unbalanced brackets, etc!
  452. *         ==> compile DEF module before running that macro
  453. *       - DEF modules containing more than 1 section (default = 32K)
  454. *         ==> remove some lengthy comments
  455. *       - if some keywords (i.e: PROCEDURE, END) appear in comments or types.
  456. *         ==> correct manually (anyway: the compiler will notice these errors).
  457. "Module DEF->MOD"  {
  458. * first copy all to a new window:
  459.     Select( 0,0 );
  460.     IF NOT Find( "DEFINITION" )  {
  461.       Alert( "Not as a definition module recognized!" ); }
  462.     ELSE  {
  463.       Select( 0,0 | L$,C$ );
  464.       Copy;
  465.       New;
  466.       Paste;
  467. * substitute DEFINITION by IMPLEMENTATION:
  468.       Select( 0,0 );
  469.       Push;
  470.       Find( "DEFINITION" );
  471.       Clear;
  472.       Insert( "IMPLEMENTATION" );
  473.       Find( " MODULE " );
  474.       Select( L.,C: );
  475.       EFind( "[A-Za-z][A-Za-z0-9]*" );
  476.       Set( $0, $S );
  477. * replace header comment (these string are written by macro "MODULE DEF"):
  478.       Select( L.+1,0 );
  479.       IF Find("(**************************************************")  {
  480.         Select( L.,0 );
  481.         Push;
  482.         Select( L.,C$-3 );
  483.         IF NOT Find("***************************************************)")
  484.           Find("*)");
  485.         Select(L[,C[ | L:,C:)!;
  486.         Drop;
  487.         Clear;
  488.       };
  489.       Call(36);
  490. * leave imports as they are:
  491.       WHILE Find ("IMPORT " )  {
  492.         Find( ";" );
  493.         IF C. = C$    Select( L.+1,0 )
  494.         ELSE          Select( L.  ,C.+1 );
  495.       };
  496. * clear heading const, type, var declarations:
  497. * note: const, type or var later inbetween procs are not filtered!
  498.       Push;
  499.       IF Find( "PROCEDURE " ) {
  500.         Select(L[,C[|L.-1,C$);
  501.         Clear;
  502.         Insert( "\N\N" );  };
  503.       Drop;
  504. * do procedures:
  505.       Select( L.,C.| L$,C$ );
  506.       Call(15);
  507. * make body:
  508.       Select( L$-10,0 );
  509.       WHILE Find( "END " )  {};
  510.       Select( L.,0 );
  511.       IF Find("END ")  {
  512.         Select( L.,0 );
  513.         Insert( "\N" );
  514.         Insert( "BEGIN\N ");
  515.         Insert( "  (*.Statement.*)\N" );  }
  516.       ELSE
  517.         Alert( "Bad syntax, no 'END' of module encountered!" );
  518.     };
  519.     Call(38);
  520.     QSavAs( Concat($0,".MOD") );
  521. };
  522.  
  523.  
  524.  
  525.  
  526. * 14
  527. * insert a PROCEDURE template (Option^P)
  528. "PROCEDURE           Opt P" 335 {
  529.   Push;
  530.   IF Prompt("Enter Procedure name",$2) {
  531.     Insert("PROCEDURE "); Insert($2);
  532. *af*    Insert(";(*. VAR .*)\n");
  533. *jt*    Insert(";(*. VAR .*)\n");
  534. *or*    Insert("( (*. VAR .*) );(*. .*)\n");
  535. *tn*    Insert(";(*. .*)\n");
  536.     Insert("( (*. VAR .*) );(*. .*)\n");
  537. *    Insert("  CONST  (*.Constants.*);\n");
  538. *    Insert("TYPE  (*.Types.*);\n");
  539. *    Insert("  VAR  (*.Variables.*);\n");
  540. *    Insert("\b\bBEGIN\n  (*.Statement.*)\n\b\bEND ");
  541.     Insert("BEGIN\n  (*.Statement.*)\n\b\bEND ");
  542.     Insert($2);
  543.     Insert(";(*. continue... .*)");    
  544.     Call(38);
  545.   };
  546. };
  547.  
  548.  
  549. * 15
  550. * expand the header of a "DEF" procedure to an empty implementation
  551. * assumes that the headers of procs to be expanded are selected before call
  552. * (supports recursive comments in argument list)
  553. * NOTE: that procedure will NOT function CORRECTLY if the brackets of
  554. *   comments or argument list are not balanced!
  555. "Proc[s] DEF->MOD"  {
  556.     Set( #1, L$ );
  557.     Select( L.,C. );
  558.     Push;
  559.     WHILE Find( "PROCEDURE " )  AND  L. < #1  {
  560.       Select( L.,C: );
  561.       EFind( "[A-Za-z][A-Za-z0-9]*" );
  562.       Set( $3, $S );
  563.       Set( #0, -1 );
  564.       IF EFind( "[;(]" )  {
  565.         IF Ord($S) = Ord(";")
  566.           Set( #0, 0 )
  567.         ELSE  {
  568.           Set( #0, 1 );
  569.           WHILE #0 > 0  {
  570.             IF EFind( "[()]" )  {
  571.               IF Ord($S) = Ord("(")  Set( #0, #0+1 )
  572.               ELSE  Set( #0, #0-1 );  }
  573.             ELSE
  574.               Set( #0, -1 );
  575.           };
  576.           IF #0 < 0  OR  NOT Find( ";" )  Set( #0, -1 );
  577.         };
  578.         IF #0 = 0  {
  579.           Select( L.+1, 0 );
  580.           Push;
  581.           Find( "(*" );
  582.           IF L. = L[  {
  583.             IF Find( "*)" )  {
  584.               Select( L[,C[ | L.,C: );
  585.               Clear;
  586.               Drop; }
  587.             ELSE
  588.               Pop;
  589.           }
  590.           ELSE
  591.             Pop;
  592.           Insert( "    (*. VAR .*)\N" );
  593.           Insert( "  BEGIN\N" );
  594.           Insert( "    (*.Statement.*)\N" );
  595.           Insert( "  END " );  Insert( $3 );  Insert( ";\N\N" );
  596. *         we have to add the number of inserted lines to update orig. selection
  597.           Set (#1, #1+5);  }
  598.         }
  599.       ELSE
  600.         Alert( "Bad syntax, no ';' found!" );
  601.     };
  602.     Call(38);
  603. };
  604.  
  605.  
  606.  
  607. * 16
  608. * insert a FOR-TO-DO template (Option^F)
  609. "FOR                       Opt F" 303 {
  610.     Push;
  611.     Insert("FOR (*.loop var.*):= (*.expr.*) TO (*.expr.*) DO\n");
  612.     Insert("  (*.Statement.*)\n");
  613.     Insert("\b\bEND(*FOR*);(*. continue... .*)");    
  614.     Call(38);
  615. };
  616.  
  617.  
  618. * 17
  619. * insert a CASE template (Option^S)
  620. "CASE                     Opt S" 301 {
  621.     Push;
  622.     Insert("CASE (*.expr.*) OF\n");
  623.     Insert("  (*.Constant.*)   : (*.Statement.*)\n");
  624.     Insert("\b\b| (*.Constant.*)   : (*.Statement.*)\n");
  625. *    Insert("\b\bELSE\N  (*.Statement.*);\n");
  626.     Insert("END(*CASE*);(*. continue... .*)");    
  627.     Call(38);
  628. };
  629.  
  630.  
  631. * 18
  632. * insert an IF-THEN-ELSE template (Option^I)
  633. * af version: Option^J is similar to Option^I
  634. * Using I may cause problems since I is diacritical with US-ASCII 
  635. * keyboard, i.e. the first character z typed will eventually carry 
  636. * a "^" if z may be used for a diacritical construction; otherwise
  637. * z will be preceeded by a "^".  In any case the user must first
  638. * delete these characters before he may (re)start with actual typing.
  639. * Remark: Option^J has nothing to do with macro Command J (Jump to line
  640. *         with a particular #)
  641. *af*"IF THEN                 Opt J" 338
  642. *jt*"IF THEN                 Opt J" 338
  643. *or*"IF THEN                 Opt I" 334
  644. *tn*"IF THEN                 Opt I" 334
  645. "IF THEN                 Opt J" 338
  646. {    Push;
  647.     Insert("IF (*.Condition.*) THEN\n  (*.Statement.*)\n");
  648.     Insert("\b\bELSE\n  (*.Statement.*)\n");
  649.     Insert("\b\bEND(*IF*);(*. continue... .*)");    
  650.     Call(38);
  651. };
  652.  
  653.  
  654. * 19
  655. *  Insert a WHILE-DO-END template (Option^W)
  656. "WHILE                   Opt W" 313 {
  657.     Push;
  658.     Insert("WHILE (*.Condition.*) DO\n");
  659.     Insert("  (*.Statement.*)\n");
  660.     Insert("\b\bEND(*WHILE*);(*. continue... .*)");    
  661.     Call(38);
  662. };
  663.  
  664.  
  665. * 20
  666. *  Insert a REPEAT-UNTIL template (Option^R)
  667. "REPEAT                  Opt R" 315 {
  668.     Push;
  669.     Insert("REPEAT\n");
  670.     Insert("  (*.Statement.*)\n");
  671.     Insert("\b\bUNTIL (*. Condition .*);(*. continue... .*)");    
  672.     Call(38);
  673. };
  674.  
  675.  
  676. * 21
  677. *  Insert a WITH-DO-END template (Option^H)
  678. "WITH                     Opt H" 304 {
  679.     Push;
  680.     Insert("WITH (*.Designator.*) DO\n");
  681.     Insert("  (*.Statement.*)\n");
  682.     Insert("\b\bEND(*WITH*);(*. continue... .*)");    
  683.     Call(38);
  684. };
  685.  
  686.  
  687. * --------------------------------------------------------------------------------
  688. * 22
  689. * insert a line in the menu
  690. "-" {};
  691.  
  692.  
  693.  
  694. * 23
  695. * puts comment-braces (like placeholders) around the current selection
  696. "Comment/K" {
  697.     Push;
  698.     Select(L],C]);
  699.     Insert(" .*)");
  700.     Select(L[,C[);
  701.     Insert("(*. ");
  702.     Pop;
  703.     IF L. = L:  Select(L.,C. | L:,C:+8)
  704.     ELSE        Select(L.,C. | L:,C:+5);
  705. };
  706.  
  707.  
  708. * 24
  709. * removes comment-braces at start and end of the current selection 
  710. * af version: (Option^K)
  711. *af*"Uncomment          Opt K" 340
  712. *jt*"Uncomment          Opt K" 340
  713. *or*"Uncomment/U" 340
  714. *tn*"Uncomment/U" 340
  715. "Uncomment          Opt K" 340 
  716. {
  717.     Push;
  718.     Select(L],C]-4 | L],C]);
  719.     Clear;
  720.     Select(L[,C[ | L[,C[+4);
  721.     Clear;
  722.     Pop;
  723. };
  724.  
  725.  
  726.  
  727.  
  728. * 25
  729. * Move all lines in the current selection to the right by inserting
  730. * a double space. do nothing for empty lines.
  731. "Move sel. right/R" {
  732.     Push;
  733.     WHILE L. < L] {
  734.         Select(L.,0);
  735.         IF NOT C$ = 0  Insert("  ");
  736.         Select(L.+1,0)!;
  737.     };
  738.     Select(L[,0|L],0);
  739.     Drop;
  740. };
  741.  
  742.  
  743. * 26
  744. * Move all lines in the current selection one position to the left
  745. * by deleting the leftmost characters. do nothing for empty lines.
  746. "Move sel. left/L" {
  747.     Push;
  748.     WHILE L. < L] {
  749.         Select(L.,0|L.,1);
  750.         Clear;
  751.         Select(L.+1,0)!;
  752.     };
  753.     Select(L[,0|L],0);
  754.     Drop;
  755. };
  756.  
  757.  
  758.  
  759. * 27
  760. * Replace all 'real' tabs by blank strings
  761. * this is useful to convert 'Edit'- to 'MEdit'-files
  762. "Replace tabs" {
  763.     SECT(0);
  764.     Select(0,0);
  765.     WHILE FIND("\9")   Insert("\t");
  766.     BEEP;
  767. };
  768.  
  769.  
  770. * 28
  771. * rearrange comments by wrapping the end of 
  772. * too long lines to the next line or filling lines too short lines
  773. * The comment must already contain comment braces such as "(*" and "*)"
  774. * and the Auto indent on resp. Line wrap around mode off!!!!!
  775. "Wrap comments/A" {
  776. * save current selection and assign last line of selection to #1
  777.     Push; Set(#1,L]);
  778. * set cursor to begin of selection and search for comment begin
  779.     Select(L[,C[); FIND("(*");
  780. * add at end of comment begin a new line in any case, update #1
  781.     Select(L.,C:); Insert("\n  "); Set(#1,#1+1);
  782. * save current selection, which is left margin of comment text
  783.     Push;
  784. * select and clear any blanks or empty lines till begin of text
  785.     WHILE C> = -1 { Select(L.+1,C>) ; Set(#1,#1-1) };
  786.     Select(L.,C>);
  787.     Select(L[,C[ | L:,C<); Clear; Drop;
  788. * WHILE comment:
  789.     WHILE L. < #1
  790.     {
  791. * IF line is too long insert after last whole word an EOL (wrap
  792. * around mode), update #1
  793.         IF C$ > 68
  794.         {
  795.           Select(L.,68); Select(L.,C<);
  796.           Insert("\n"); Set(#1,#1+1);
  797.         }
  798. * ELSE current line is too short, hence remove EOL, update #1, and 
  799. * remove all blanks except for one till begin of next word (fill mode)
  800. * unless it is the last line
  801.         ELSE
  802.         {
  803.           IF L. < #1-1
  804.           {
  805.             Select(L.,C$ | L.+1,0); Clear; Set(#1,#1-1);
  806.             Select(L.,C<); Select(L.,C>); Insert(" ");
  807.             Push;
  808.             Select(L.,C>); Select(L[,C[ | L.,C<); Clear; Drop;
  809.           } ELSE Set(#1,#1-1);
  810.         };
  811.     };
  812. * Find "*)" which is on the current line (was filled in) and
  813. * insert an EOL before it, shift it to the left by 2 columns
  814.     Select(L.,0); FIND("*)"); Select(L.,C.);
  815.     Insert("\n");
  816.     Select(L.,C.-2 | L.,C.);  Clear;
  817. * Add an EOL after comment (has been removed during fill in) and
  818. * restore selection
  819.     Select(L.,C$); Insert("\N");
  820.     Select(L[,C[ | L.,0)!;
  821.     Drop;
  822. };
  823.  
  824.  
  825. * 29
  826. * rearrange text by wrapping the end of 
  827. * too long lines to the next line or filling lines too short lines
  828. * Option ^ W (works if text not commented (s.a. Macro 22)
  829. * left margin of text is given by first word begin in selection
  830. "Wrap text             Opt A" 300 {
  831. * save current selection and assign last line of selection to #1
  832.     Push; Set(#1,L]);
  833. * set cursor to begin of selection
  834.     Select(L[,C[);
  835. * WHILE text:
  836.     WHILE L. < #1
  837.     {
  838. * IF line is too long insert after last whole word an EOL (wrap
  839. * around mode), update #1
  840.         IF C$ > 68
  841.         {
  842.           Select(L.,68); Select(L.,C<);
  843.           Insert("\n"); Set(#1,#1+1);
  844.         }
  845. * ELSE current line is too short, hence remove EOL, update #1, and 
  846. * remove all blanks except for one till begin of next word (fill mode)
  847. * unless it is the last line
  848.         ELSE
  849.         {
  850.           IF L. < #1-1
  851.           {
  852.             Select(L.,C$ | L.+1,0); Clear; Set(#1,#1-1);
  853.             Select(L.,C<); Select(L.,C>); Insert(" ");
  854.             Push;
  855.             Select(L.,C>); Select(L[,C[ | L.,C<); Clear; Drop;
  856.           } ELSE Set(#1,#1-1);
  857.         };
  858.     };
  859. * Add an EOL after text (has been removed during fill in) and
  860. * restore selection
  861.     Select(L.,C$); Insert("\N");
  862.     Select(L[,C[ | L.,0)!;
  863.     Drop;
  864. };
  865.  
  866.  
  867. * --------------------------------------------------------------------------------
  868. * 30
  869. * insert a line in the menu (line separator)
  870. "-" {};
  871.  
  872. *-*************-*
  873. *-* Movements *-*
  874. *-*************-*
  875.  
  876.  
  877. * 31
  878. * Bring last window to front
  879. "Flip windows/H"  {
  880.     Set(#0,0);  WHILE Window(#0)  Set(#0,#0+1);  Window(#0-1);
  881. };
  882.  
  883.  
  884. * 32
  885. * Ask for a line number to jump to and do it
  886. "Jump to Line/J" {
  887.     Prompt("Goto Line",#6);
  888.     Select(#6-1,C. | #6-1,C.)!;
  889. };
  890.  
  891.  
  892. * 33
  893. * jumps to the next placeholder in a Modula-2 structure
  894. * Alternative keyboard entry: Option^G ~ 305
  895. *af*"Placeholder          Opt G/G" 305
  896. *jt*"Placeholder          Opt G/G" 305
  897. *or*"Placeholder          Opt -" 344
  898. *tn*"Placeholder          Opt -" 344
  899. "Placeholder          Opt G/G" 305 
  900. {
  901.     Find("(*.");
  902.     IF L: = 0 AND C: = 0   Find("(*.");
  903.     Push;
  904.     Find(".*)");
  905.     Select(L[,C[ | L:,C:)!;
  906.     Drop;
  907. };
  908.  
  909.  
  910. * 34
  911. * For use together with the following macros
  912. "Save position/B" {
  913.     Push;
  914. };
  915.  
  916.  
  917. * 35
  918. * Jumps back to the last position saved with macro 2 (Option^B)
  919. * the stack can hold the last eight positions
  920. "Back to position   Opt B" 311 {
  921.     Select(L[,C[)!;
  922.     Pop;
  923. };
  924.  
  925.  
  926.  
  927. *==================================================================*
  928. * !!! From here on depending on the version macros with or without *
  929. * menu entries. NOTE: macros with menu entries will function only  *
  930. * properly if they are defined in a sequence from the beginning    *
  931. * without ANY! macro stuck in between WITHOUT menu entry !!!       *
  932. *==================================================================*
  933.  
  934. * ………
  935.  
  936.  
  937. *============================================================*
  938. * !!! Add from here on only(!) macros with NO menu entry !!! *
  939. *============================================================*
  940.  
  941.  
  942. * 36
  943. * insert implementation header info:
  944.     {
  945.       Insert("  (*\N");
  946.       Insert("        Implementation and Revisions:\N");
  947.       Insert("        ============================\N");
  948.       Insert("\N");
  949.       Insert("        Author  Date        Description\N");
  950.       Insert("        ------  ----        -----------\N");
  951.       Insert("\N");
  952.       Insert(Concat("        ",SubStr($6,0,1),SubStr($7,0,1),"      ",Date(2)));
  953.       Insert("    First implementation (MacMETH_V3.2.3)\N");
  954.       Insert("\N");
  955.       Insert("  *)\N");
  956.       Insert("\N");
  957.       Insert("\N");
  958.       Insert("  (*.imports.*)\N");
  959. };
  960.  
  961. * 37
  962. * delete to end of line   option - BS ~ 351
  963. 351 {
  964.     Select(L.,C.|L.,C$);
  965.     Clear;
  966. };
  967.  
  968.  
  969. * 38
  970. * select first placeholder
  971. * !!!! this macro is called by many other macros !!!!
  972. {
  973.     Pop;
  974.     Find("(*.");
  975.     Push;
  976.     Find(".*)");
  977.     Select(L[,C[ | L:,C:)!;
  978.     Drop;
  979. };
  980.  
  981.  
  982. * 39
  983. * select current word (like double click)
  984. *: <Enter>
  985. (1,76)
  986. {
  987.     Select(L.,C< | L.,C>)!;
  988. }.
  989.  
  990. * --------------------------------------------------------------------------------
  991. *** only a maximum of 60 macros are supported by the MComp = V1.40 ***
  992.